package com.clouddo.clouddologin.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.clouddo.clouddologin.dao.UserDao;
import com.clouddo.clouddologin.model.User;

@Service
public class UserServiceImpl implements UserService{
	
	private static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	public UserServiceImpl() {
		// TODO Auto-generated constructor stub
	}
	
	@Autowired
	UserDao loginDao;

	public List<User> list() {
		// TODO Auto-generated method stub
		List<User> list = loginDao.list();
		return list;
	}

	public int save(User user) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		user.setCreatetime(formatter.format(new Date()));
		int save = loginDao.save(user);
		return save;
	}

	public int update(User user) {
		// TODO Auto-generated method stub
		int update = loginDao.update(user);
		return update;
	}

	public int remove(String username) {
		// TODO Auto-generated method stub
		int remove = loginDao.remove(username);
		return remove;
	}

	public String get(String username) {
		// TODO Auto-generated method stub
		logger.info("user = {} "+username);
		return loginDao.get(username);
	}


}
